package com.qtenv.datasync.service.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qtenv.datasync.service.entity.TerminalHistoryData;
import com.qtenv.datasync.service.mapper.TerminalHistoryDataMapper;
import com.qtenv.datasync.service.service.TerminalHistoryDataService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 历史数据（大表） 服务实现类
 * </p>
 *
 * @author CBL
 * @since 2022-06-22
 */
@Service
@DS("master")
public class TerminalHistoryDataServiceImpl extends ServiceImpl<TerminalHistoryDataMapper, TerminalHistoryData> implements TerminalHistoryDataService {

    @Override
//    @DS("middle")
    public List<TerminalHistoryData> findRecords(String startTime, String endTime) {
        return this.list(new QueryWrapper<TerminalHistoryData>().ge("ReadDate", startTime).le("ReadDate", endTime));
    }

    @Override
    //@DS("middle")
    public void saveToMiddle(List<TerminalHistoryData> dataList) {
        this.getBaseMapper().insertAllBatch(dataList);
    }

    @Override
    public List<TerminalHistoryData> getInstantDataList(String tenantId, String areaId, String startDate, String endDate) {
        return this.getBaseMapper().getInstantDataList(tenantId, areaId, startDate, endDate);
    }

    @Override
    public List<TerminalHistoryData> getHistoryDataList(String tenantId, String terminalId, String startDate, String endDate) {
        return this.getBaseMapper().getHistoryDataList(tenantId, terminalId, startDate, endDate);
    }

    @Override
    public List<TerminalHistoryData> getSeniorMinNightFlow(String tenantId, String areaId) {
        return this.getBaseMapper().getSeniorMinNightFlow(tenantId, areaId);
    }
}
